#include "threadPool.hpp"
#include "Task.hpp"
#include "log.hpp"

int main()
{
    // logMessage(NORMAL, "%s %d %c %f", "这是一条日志信息", 1234, 'c', 3.14);

    srand((unsigned int)time(NULL) ^ getpid());
    // ThreadPool<Task> *tp = new ThreadPool<Task>();
    // ThreadPool<Task> *tp = ThreadPool<Task>::getThreadPool(5);
    // 那么，如果单例本身也在被多线程申请使用呢？
    ThreadPool<Task>::getThreadPool()->run();

    while (true)
    {
        // 生产的过程，制作任务的时候，要花时间
        int x = rand() % 100;
        usleep(8000);
        int y = rand() % 30 + 1;
        Task t(x, y, [](int x, int y)->int{ return x + y; });
        // cout << "制作任务完成: " << x << "+" << y << "=?" << endl;
        logMessage(DEBUG, "制作任务完成: %d+%d=?", x, y);

        // 推送任务到线程池中
        ThreadPool<Task>::getThreadPool()->pushTask(t);

        sleep(1);
    }

    return 0;
}